package common

import (
	"time"

	"github.com/panjf2000/ants/v2"
	"github.com/shirou/gopsutil/cpu"
)

func TaskRuner(tasks ...func()) {

	pool, _ := ants.NewPool(len(tasks))
	for _, t := range tasks {
		pool.Submit(t)
	}

	defer pool.Release()
}

func CpuTask() {
	for {
		percent, _ := cpu.Percent(time.Second, false)

		MsgQueue.Enqueue(&Msg{
			Type: "cpu_info",
			Data: percent[0],
		})
		time.Sleep(time.Second * 3)
	}
}
